#ifndef __SLOTHTTPD_CONFIG_CONFIG_HPP__
#define __SLOTHTTPD_CONFIG_CONFIG_HPP__

#include <slothttpd/types.hpp>
#include <slothttpd/config/fcgi_app.hpp>

#include <string>
#include <vector>
#include <ostream>

#include <boost/shared_ptr.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/asio/io_service.hpp>

namespace slothttpd {
namespace config {

class server;
typedef boost::shared_ptr<server> server_ptr;

class configuration;
typedef boost::shared_ptr<configuration> configuration_ptr;

class configuration
{
public:
    configuration(const boost::property_tree::ptree &root);
    void handle_uri(connection_ptr c);
    
    static configuration_ptr from_file(const std::string &filename);
    static configuration_ptr instance;
    
public:
    struct buffer_list
    {
        std::size_t size;
        std::size_t nmax;
    };
    
    std::string             log_file;
    
    std::string             bound_address;
    unsigned                port;
    
    unsigned                workers;
    
    size_t                  pool_size;
    
    buffer_list             receive_buffers;
    
    // TODO: make max_content_length location dependend
    size_t                  max_content_length;
    
    std::vector<server_ptr> servers;
    std::vector<fcgi_app_ptr> fcgi_apps;
    
    // module_type  modules
};

std::ostream &operator<<(std::ostream &os, const configuration::buffer_list &b);
std::ostream &operator<<(std::ostream &os, const configuration &c);

}
}

#endif
